/**
 备件看板
 **/
import { http } from "@/utils/http";

export interface SearchParams {
  typeCode?: string;
  parentCode?: string;
  sparePartName?: string;
  specification?: string;
  startTime?: string;
  endTime?: string;
}

export interface OverviewDataType {
  todayInNum: number;
  todayInRingRatio: number;
  todayOutNum: number;
  todayOutRingRatio: number;
  monthInNum: number;
  monthInRingRatio: number;
  monthOutNum: number;
  monthOutRingRatio: number;
  totalNum: number;
  warningNum: number;
}

export interface ResponseDataOfInDateAnalysisItem {
  name: string;
  value: number;
}

export type ResponseDataOfInDateAnalysis = ResponseDataOfInDateAnalysisItem[];

export interface ResponseDataOfHealthItem {
  code: string;
  name: string;
  value: number;
  children?: ResponseDataOfHealthItem[];
}

type ResponseDataOfTypeItem = Pick<ResponseDataOfHealthItem, "code" | "name"> & {
  inValue: number;
  outValue: number;
};

export type ResponseDataOfHealth = ResponseDataOfHealthItem[];

export interface ResponseDataOfInAndOutCountTrend {
  inNumList: number[];
  outNumList: number[];
  keyList: string[];
  dayTrend: Record<string, ResponseDataOfInAndOutCountTrend> | null;
}

export type ResponseDataOfInAndOutTrend = ResponseDataOfTypeItem[];

// 备件总览
export const getOverview = () => {
  return http.request<OverviewDataType>("post", "/erc/api/v1/sparePart/sparePartGeneral");
};
// 入库时间分析
export const getDataOfInDateAnalysis = (data?: SearchParams) => {
  return http.request<ResponseDataOfInDateAnalysis>("post", "/erc/api/v1/sparePart/inTimeAnalyse", {
    data
  });
};
// 库存健康分析
export const getDataOfStockHealthAnalysis = (data?: SearchParams & { isTop: boolean }) => {
  return http.request<ResponseDataOfHealth>("post", "/erc/api/v1/sparePart/stockHealthAnalyse", {
    data
  });
};
// 出入库数量趋势
export const getDataOfInAndOut = (data?: SearchParams) => {
  return http.request<ResponseDataOfInAndOutCountTrend>("post", "/erc/api/v1/sparePart/inOutNumTrend", {
    data
  });
};
// 出入库种类分析
export const getDataOfInAndOutType = (data?: SearchParams & { isTop: boolean }) => {
  return http.request<ResponseDataOfInAndOutTrend>("post", "/erc/api/v1/sparePart/inOutTypeTrend", {
    data
  });
};
